package refactortips.editors.refactorings;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.SWTResourceManager;

import refactortips.editors.AbstractRefactorTipsEditor;
import org.eclipse.wb.swt.ResourceManager;

public class ExtractMethodEditor extends AbstractRefactorTipsEditor {

	protected final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
	
	public ExtractMethodEditor() {
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		Form frmRefactoring = formToolkit.createForm(parent);
		formToolkit.paintBordersFor(frmRefactoring);
		frmRefactoring.setText("Extract Method");
		frmRefactoring.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(frmRefactoring.getBody(), SWT.NONE);
		formToolkit.adapt(tabFolder);
		formToolkit.paintBordersFor(tabFolder);
		
		ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		sc.setExpandHorizontal(true);
	    sc.setExpandVertical(true);
		
		TabItem tbtmDescription = new TabItem(tabFolder, SWT.NONE);
		tbtmDescription.setText("Descri\u00E7\u00E3o");
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmDescription.setControl(scrolledComposite);
		formToolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		Composite composite_3 = new Composite(scrolledComposite, SWT.NONE);
		formToolkit.adapt(composite_3);
		formToolkit.paintBordersFor(composite_3);
		composite_3.setLayout(null);
		
		Label lblDescription = new Label(composite_3, SWT.NONE);
		lblDescription.setBounds(10, 10, 102, 25);
		lblDescription.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblDescription.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		formToolkit.adapt(lblDescription, true, true);
		lblDescription.setText("Descri\u00E7\u00E3o");
		
		Label lblVocPossuiUm = new Label(composite_3, SWT.NONE);
		lblVocPossuiUm.setText("Voc\u00EA possui um fragmento de c\u00F3digo que pode ser agrupado junto.\r\nTransforme o fragmento em um m\u00E9todo cujo nome explica o prop\u00F3sito do m\u00E9todo.");
		lblVocPossuiUm.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		lblVocPossuiUm.setAlignment(SWT.CENTER);
		lblVocPossuiUm.setBounds(117, 69, 602, 63);
		formToolkit.adapt(lblVocPossuiUm, true, true);
		
		Label label_1 = new Label(composite_3, SWT.NONE);
		label_1.setText("Motiva\u00E7\u00E3o");
		label_1.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		label_1.setBounds(10, 162, 98, 25);
		formToolkit.adapt(label_1, true, true);
		
		StyledText styledText = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText.setText("\t\tExtract Method \u00E9 um das refatora\u00E7\u00F5es mais comuns que eu realizo. Eu olho para um m\u00E9todo que \u00E9 muito longo ou para um c\u00F3digo que precisa de um coment\u00E1rio para entender o seu prop\u00F3sito. Em seguida eu transformo esse fragmento de c\u00F3digo em seu pr\u00F3prio m\u00E9todo.");
		styledText.setJustify(true);
		styledText.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText.setEnabled(false);
		styledText.setDoubleClickEnabled(false);
		styledText.setBounds(29, 202, 803, 63);
		formToolkit.adapt(styledText);
		formToolkit.paintBordersFor(styledText);
		
		StyledText styledText_1 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_1.setText("\t\tEu prefiro m\u00E9todos curtos e com um bom nome por v\u00E1rias raz\u00F5es. Primeiro, aumenta as chances que outros m\u00E9todos possam usar um m\u00E9todo quando o m\u00E9todo est\u00E1 finamente granulado. Segundo, permite que os m\u00E9todos de um n\u00EDvel mais alto sejam lidos mais como uma s\u00E9rie de coment\u00E1rios. Sobrescrita tamb\u00E9m \u00E9 mais f\u00E1cil quando os m\u00E9todos est\u00E3o finamente granulados.");
		styledText_1.setJustify(true);
		styledText_1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_1.setEnabled(false);
		styledText_1.setDoubleClickEnabled(false);
		styledText_1.setBounds(29, 278, 803, 98);
		formToolkit.adapt(styledText_1);
		formToolkit.paintBordersFor(styledText_1);
		
		StyledText styledText_2 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_2.setText("\t\tLeva um certo tempo se acostumar se voc\u00EA est\u00E1 acostumado com m\u00E9todos maiores. E m\u00E9todos menores realmente funcionam apenas quando voc\u00EA t\u00EAm bons nomes, ent\u00E3o voc\u00EA precisa prestar aten\u00E7\u00E3o ao nomear. Pessoas \u00E0s vezes me perguntam qual o tamanho que eu procuro em um m\u00E9todo. Para mim, o tamanho n\u00E3o \u00E9 o problema. O ponto chave \u00E9 a dist\u00E2ncia sem\u00E2ntica entre o nome do m\u00E9todo \u00E9 o corpo do m\u00E9todo. Se extrair melhora a clareza, fa\u00E7a, mesmo se o nome seja maior que o c\u00F3digo que voc\u00EA extraiu.");
		styledText_2.setJustify(true);
		styledText_2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_2.setEnabled(false);
		styledText_2.setDoubleClickEnabled(false);
		styledText_2.setBounds(29, 378, 803, 135);
		formToolkit.adapt(styledText_2);
		formToolkit.paintBordersFor(styledText_2);
		
		Label label = new Label(composite_3, SWT.NONE);
		label.setText("Atalho");
		label.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		label.setBounds(10, 519, 78, 42);
		formToolkit.adapt(label, true, true);
		
		Label lblSelecioneUmTrecho = new Label(composite_3, SWT.NONE);
		lblSelecioneUmTrecho.setText("Selecione um trecho de c\u00F3digo e pressione");
		lblSelecioneUmTrecho.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		lblSelecioneUmTrecho.setAlignment(SWT.CENTER);
		lblSelecioneUmTrecho.setBounds(94, 522, 296, 21);
		formToolkit.adapt(lblSelecioneUmTrecho, true, true);
		
		Label lblAltShift = new Label(composite_3, SWT.NONE);
		lblAltShift.setText("Alt + Shift + M");
		lblAltShift.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.BOLD));
		lblAltShift.setAlignment(SWT.CENTER);
		lblAltShift.setBounds(412, 522, 140, 21);
		formToolkit.adapt(lblAltShift, true, true);
		scrolledComposite.setContent(composite_3);
		scrolledComposite.setMinSize(composite_3.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmUsage = new TabItem(tabFolder, SWT.NONE);
		tbtmUsage.setText("Exemplo");
		
		ScrolledComposite scrolledComposite_1 = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmUsage.setControl(scrolledComposite_1);
		formToolkit.paintBordersFor(scrolledComposite_1);
		scrolledComposite_1.setExpandHorizontal(true);
		scrolledComposite_1.setExpandVertical(true);
		
		Composite composite = new Composite(scrolledComposite_1, SWT.NONE);
		formToolkit.adapt(composite);
		formToolkit.paintBordersFor(composite);
		
		Label label_2 = new Label(composite, SWT.NONE);
		label_2.setImage(ResourceManager.getPluginImage("RefactorTips", "images/refactor/extractMethod/extractMethodSample1.1.png"));
		label_2.setBounds(10, 10, 597, 543);
		formToolkit.adapt(label_2, true, true);
		
		Label label_3 = new Label(composite, SWT.NONE);
		label_3.setImage(ResourceManager.getPluginImage("RefactorTips", "images/rightPointer.png"));
		label_3.setBounds(615, 266, 66, 36);
		formToolkit.adapt(label_3, true, true);
		
		Label label_4 = new Label(composite, SWT.NONE);
		label_4.setImage(ResourceManager.getPluginImage("RefactorTips", "images/refactor/extractMethod/extractMethodSample1.2.png"));
		label_4.setBounds(687, 10, 596, 830);
		formToolkit.adapt(label_4, true, true);
		scrolledComposite_1.setContent(composite);
		scrolledComposite_1.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmVideo = new TabItem(tabFolder, SWT.NONE);
		tbtmVideo.setText("Video");
		
		Browser browser = new Browser(tabFolder, SWT.NONE);
		browser.setUrl("www.youtube.com/embed/plzG1X-iXjc");
		tbtmVideo.setControl(browser);
		formToolkit.paintBordersFor(browser);
	}
}
